import {defineConfig, loadEnv} from 'vite'
import vue from '@vitejs/plugin-vue'
import {wrapperEnv} from './build/getEnv'

// https://vitejs.dev/config/

export default defineConfig(({mode}) => {
  const root = process.cwd()
  const env = loadEnv(mode, root)
  const viteEnv = wrapperEnv(env)
  return {
    plugins: [vue()],
    envPrefix: ['VITE_', 'XIOA_'],
    server: {
      https: viteEnv.VITE_HTTPS,
      port: viteEnv.VITE_PORT,
      host: viteEnv.VITE_HOST,
      open: viteEnv.VITE_OPEN,
      cors: viteEnv.VITE_CORS
    },
    esbuild: {
      pure: viteEnv.VITE_DROP_CONSOLE ? ["console.log", "debugger"] : []
    },
    build: {
      outDir: "dist",
      minify: "esbuild",

      rollupOptions: {
        output: {
          chunkFileNames: "assets/js/[name]-[hash].js",
          entryFileNames: "assets/js/[name]-[hash].js",
          assetFileNames: "assets/[ext]/[name]-[hash].[ext]"
        }
      }
    }
  }

})
